﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ColorWheelNET.Renderers
{
    internal static class SubscriptionManager
    {
        internal static void Subscribe(CWheel wheel)
        {
            if (wheel == null || wheel.IsDisposed || wheel.Disposing) { return; }
            wheel.Unsubscribe();


            switch (wheel.DisplayStyle)
            {
                case ColorWheelDisplayStyle.Rectangle:
                    wheel.OnCalculateColorGroup = RectangleWheel.CalculateColorGroup;
                    wheel.OnCalculateLayout = RectangleWheel.CalculateLayout;
                    wheel.OnCalculateSelectedPoint = RectangleWheel.CalculateSelectedPoint;
                    wheel.OnColorHitTest = RectangleWheel.ColorHitTest;
                    wheel.OnDrawColorWheel = RectangleWheel.DrawWheel;
                    wheel.OnDrawSelector = SaturationWheel.DrawSelector;
                    wheel.OnCalculateSelectorColor = RectangleWheel.CalculateSelectorColor;
                    break;
                case ColorWheelDisplayStyle.DarkColorWheel:
                    wheel.OnCalculateColorGroup = ValueWheel.CalculateColorGroup;
                    wheel.OnCalculateLayout = ValueWheel.CalculateLayout;
                    wheel.OnCalculateSelectedPoint = ValueWheel.CalculateSelectedPoint;
                    wheel.OnColorHitTest = ValueWheel.ColorHitTest;
                    wheel.OnDrawColorWheel = ValueWheel.DrawWheel;
                    wheel.OnDrawSelector = ValueWheel.DrawSelector;
                    wheel.OnCalculateSelectorColor = ValueWheel.CalculateSelectorColor;
                    break;

                case ColorWheelDisplayStyle.HSVTriangle:
                    wheel.OnCalculateColorGroup = HSVTriangle.CalculateColorGroup;
                    wheel.OnCalculateLayout = HSVTriangle.CalculateLayout;
                    wheel.OnCalculateSelectedPoint = HSVTriangle.CalculateSelectedPoint;
                    wheel.OnColorHitTest = HSVTriangle.ColorHitTest;
                    wheel.OnDrawColorWheel = HSVTriangle.DrawWheel;
                    wheel.OnDrawSelector = SaturationWheel.DrawSelector;//HSVTriangle.DrawSelector;
                   wheel.OnCalculateSelectorColor = RectangleWheel.CalculateSelectorColor;//HSVTriangle.CalculateSelectorColor;
                    break;
                case ColorWheelDisplayStyle.ColorWheel:
                    wheel.OnCalculateColorGroup = SaturationWheel.CalculateColorGroup;
                    wheel.OnCalculateLayout = SaturationWheel.CalculateLayout;
                    wheel.OnCalculateSelectedPoint = SaturationWheel.CalculateSelectedPoint;
                    wheel.OnColorHitTest = SaturationWheel.ColorHitTest;
                    wheel.OnDrawColorWheel = SaturationWheel.DrawWheel;
                    wheel.OnDrawSelector = SaturationWheel.DrawSelector;
                    wheel.OnCalculateSelectorColor = SaturationWheel.CalculateSelectorColor;
                    break;
            }


            //FUll INVALIDATE: Forces all calculations to be reset and redraw on the screen
            //Does NOT clear WheelRectangle, Color, or ColorGroup
            wheel.ResetInvalidate();
        }
    }
}
